from mokocard.util.ioutil import manageConfigFile

class ConfigData:

    # those methods are unnecessary if the Class remain like this. 
    # you can use directly the self variabile
    # can you improve it?
    
    def getStdoutMode(self):
        return self.stdoutMode

    def getPathLogFile(self):
        return self.pathLogFile

    def getDefaultDatabase(self):
        return self.defaultDatabase
    
    def getDefaultImportFile(self):
        return self.defaultImportFile

    def getSeparator(self):
        return self.separator
    
    def getButtonCardsHeight(self):
        print self.buttonCardsHeight
        return self.buttonCardsHeight
    
    def getButtonCardsWidth(self):
        return self.buttonCardsWidth

    def getButtonConfigHeight(self):
        return self.buttonConfigHeight
    
    def getButtonConfigWidth(self):
        return self.buttonConfigWidth

    def getButtonStatsHeight(self):
        return self.buttonStatsHeight
    
    def getButtonStatsWidth(self):
        return self.buttonStatsWidth

    def getButtonArrangeHeight(self):
        return self.buttonArrangeHeigth
    
    def getButtonArrangeWidth(self):
        return self.buttonArrangeWidth

    def getPrintableConfigData(self):
        _configData = "########  BEGIN CONFIG DATA  ########"  + "\n"
        _configData = _configData + "default_database: " + self.defaultDatabase + "\n"
        _configData = _configData + "default_import_file: " + self.defaultImportFile + "\n"
        _configData = _configData + "separator: " + self.separator + "\n"
        _configData = _configData + "path_log_file: " + self.pathLogFile + "\n"
        _configData = _configData + "stdout_mode: " + str(self.stdoutMode) + "\n"
        _configData = _configData + "BT_CARDS_HEIGHT: " + str(self.buttonCardsHeight) + "\n"
        _configData = _configData + "BT_CARDS_WIDTH: " + str(self.buttonCardsWidth) + "\n"
        _configData = _configData + "BT_CONFIG_HEIGHT: " + str(self.buttonConfigHeight) + "\n"
        _configData = _configData + "BT_CONFIG_WIDTH: " + str(self.buttonConfigWidth) + "\n"
        _configData = _configData + "BT_STATS_HEIGHT: " + str(self.buttonStatsHeight) + "\n"
        _configData = _configData + "BT_STATS_WIDTH: " + str(self.buttonStatsWidth) + "\n"
        _configData = _configData + "BT_ARRANGE_HEIGHT: " + str(self.buttonArrangeHeigth) + "\n"
        _configData = _configData + "BT_ARRANGE_WIDTH: " + str(self.buttonArrangeWidth) + "\n"
        _configData = _configData + "########  END CONFIG DATA  ########" + "\n"
        return _configData
        
    def __init__ (self, configFile):
        
        hashConfig = manageConfigFile(configFile)
        
        # initialize variables so I don't receive error using them
        self.defaultDatabase = ""
        self.defaultImportFile = ""
        self.separator = ""
        self.pathLogFile = "/tmp/mokocard.log"
        self.stdoutMode = False
        # button height / width
        self.buttonCardsHeight = -1
        self.buttonCardsWidth = -1
        self.buttonConfigHeight = -1
        self.buttonConfigWidth = -1
        self.buttonStatsHeight = -1
        self.buttonStatsWidth = -1
        self.buttonArrangeHeigth = -1
        self.buttonArrangeWidth = -1
        
        if hashConfig != None:
            if hashConfig.has_key("default_database"):
                self.defaultDatabase = hashConfig["default_database"]
            if hashConfig.has_key("default_import_file"):
                self.defaultImportFile = hashConfig["default_import_file"]
            if hashConfig.has_key("separator"):
                self.separator = hashConfig["separator"]
            if hashConfig.has_key("path_log_file"):
                self.pathLogFile = hashConfig["path_log_file"]
            if hashConfig.has_key("stdout_mode") and hashConfig["stdout_mode"].upper() == 'T':
                self.stdoutMode = True
            if hashConfig.has_key("BT_CARDS_HEIGHT"):
                try:
                    self.buttonCardsHeight = int(hashConfig['BT_CARDS_HEIGHT'])
                except:
                    print "impossibile to convert BT_CARDS_HEIGHT value #" +  hashConfig['BT_CARDS_HEIGHT'] + "#"

            if hashConfig.has_key("BT_CARDS_WIDTH"):
                try:
                    self.buttonCardsWidth = int(hashConfig['BT_CARDS_WIDTH'])
                except:
                    print "impossibile to convert BT_CARDS_WIDTH value #" +  hashConfig['BT_CARDS_WIDTH'] + "#"
                    
            if hashConfig.has_key("BT_CONFIG_HEIGHT"):
                try:
                    self.buttonConfigHeight = int(hashConfig['BT_CONFIG_HEIGHT'])
                except:
                    print "impossibile to convert BT_CONFIG_HEIGHT value #" +  hashConfig['BT_CONFIG_HEIGHT'] + "#"

            if hashConfig.has_key("BT_CONFIG_WIDTH"):
                try:
                    self.buttonConfigWidth = int(hashConfig['BT_CONFIG_WIDTH'])
                except:
                    print "impossibile to convert BT_CONFIG_WIDTH value #" +  hashConfig['BT_CONFIG_WIDTH'] + "#"
                    
            if hashConfig.has_key("BT_STATS_HEIGHT"):
                try:
                    self.buttonStatsHeight = int(hashConfig['BT_STATS_HEIGHT'])
                except:
                    print "impossibile to convert BT_STATS_HEIGHT value #" +  hashConfig['BT_STATS_HEIGHT'] + "#"

            if hashConfig.has_key("BT_STATS_WIDTH"):
                try:
                    self.buttonStatsWidth = int(hashConfig['BT_STATS_WIDTH'])
                except:
                    print "impossibile to convert BT_STATS_WIDTH value #" +  hashConfig['BT_STATS_WIDTH'] + "#"

            if hashConfig.has_key("BT_ARRANGE_HEIGHT"):
                try:
                    self.buttonArrangeHeigth = int(hashConfig['BT_ARRANGE_HEIGHT'])
                except:
                    print "impossibile to convert BT_ARRANGE_HEIGHT value #" +  hashConfig['BT_ARRANGE_HEIGHT'] + "#"

            if hashConfig.has_key("BT_ARRANGE_WIDTH"):
                try:
                    self.buttonArrangeWidth = int(hashConfig['BT_ARRANGE_WIDTH'])
                except:
                    print "impossibile to convert BT_ARRANGE_WIDTH value #" +  hashConfig['BT_ARRANGE_WIDTH'] + "#"